import { IotAttr } from "_common/entity";
import { createRequest, RequestMethod } from "_common/request";
import { AxiosInstance } from "axios";

/**
 * @Author: easten
 * @Created: 2024-07-31 23:37:15
 * @Description:  产品属性管理
 *
 *
 */
export class ApiAttr {
  /**
   * @description 请求实例
   * @type {RequestMethod}
   * @memberof ApiDevice
   * */
  request: RequestMethod;
  url: string = "api/iot/attr/";

  /**
   * @description 构造函数
   * @param config axios 配置
   */
  public constructor(instance: AxiosInstance) {
    // axios 实例化
    this.request = createRequest(instance);
  }
  createAttr(data: IotAttr) {
    return this.request.post<boolean>(this.url, data);
  }

  /** 更新属性 */
  updateAttr(data: IotAttr) {
    return this.request.put<boolean>(this.url, data);
  }

  /** 删除属性 */
  deleteAttr(id: number) {
    return this.request.delete<boolean>(this.url + id);
  }

  /** 获取属性信息 */
  getAttrInfo(id: number) {
    return this.request.get<IotAttr>(this.url + "get-attr", { id });
  }

  /** 获取属性列表 */
  getAttrList() {
    return this.request.get<IotAttr[]>(this.url + "get-list");
  }

  // 获取属性分页列表
  getPageList(params: any) {
    return this.request.get<any>(this.url + "get-page", params);
  }
}
